package com.sykj.why.util;

import com.aliyun.oss.OSSClient;
import com.sykj.why.exception.WhyException;
import com.sykj.why.mongo.enums.exception.ResultEnum;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;

import java.io.File;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class BaseTools {

    // 默认时间
    public static String DEFAULTTIME = "2010-06-25 12:48:21";

    //日期格式化yyyyMMdd
    public static final String DATEFORMATEYMD = "yyyyMMdd";

    //日期格式化yyyyMMddHHmmss
    public static final String DATEFORMATEYMDHMS = "yyyyMMddHHmmss";

    private static String serverPath = "http://jcjjwhy.oss-cn-hangzhou.aliyuncs.com/";
    /**
     * 目标地址
     */
    public static final String ENDPOINT = "http://oss-cn-hangzhou.aliyuncs.com";

    /**
     * 你的Access Key ID
     */
    public static final String ACCESS_KEY_ID = "LTAI2bSSZ73PKL9S";

    /**
     * 你的Access Key Secret
     */
    public static final String ACCESS_KEY_SECRET = "2wRpXTohmUMass3FswcqHJ0vJpIyMx";

    /**
     * 目标空间
     */
    public static final String BUCKET_NAME = "jcjjwhy";

    private static String uploadUrl = "/home/images/";

    private static String[] weeks = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};

    /**
     * 设置日期格式
     *
     * @return
     */
    public static String tagdate() {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        String time = formatter.format(cal.getTime()).toString();
        return time;
    }

    public static Date defaulttime() {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
            Date date = sdf.parse(DEFAULTTIME);
            return date;
        } catch (ParseException e) {

        }
        return null;

    }



    /**
     * 转换小时分秒
     *
     * @param memberdelivertime
     * @return
     */
    public static Date getStringtoDate(String memberdelivertime) {

        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss", Locale.CHINA);
        Date date = null;
        try {
            date = formatter.parse(memberdelivertime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    /**
     * 获取系统时间
     *
     * @return
     * @throws ParseException
     */
    public static Date systemtime() {
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String dateString = formatter.format(date);
        ParsePosition pos = new ParsePosition(0);
        Date currenttime = formatter.parse(dateString, pos);
        return currenttime;
    }

    /**
     * 获取系统时间
     *
     * @return
     */
    public static String systemtime2() {
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        String dateString = formatter.format(date);
        return dateString;
    }


    /**
     * 获取系统时间long
     *
     * @return
     * @throws ParseException
     */
    public static long systemtimeLong() {
        return System.currentTimeMillis();
    }


    /**
     * 获取当前系统时间的用户可视时间
     *
     * @return
     */
    public static String systemtimeString(String style) {
        if (StringUtils.isBlank(style)) {
            style = "yyyy-MM-dd HH:mm:ss";
        }
        SimpleDateFormat formatter = new SimpleDateFormat(style, Locale.CHINA);
        String dateString = formatter.format(new Date());
        return dateString;
    }


    /**
     * 转换数据库日期格式
     *
     * @param object
     * @return
     */
    public static String formateDbDate(Date object) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String dateString = formatter.format(object);
        return dateString;
    }

    /**
     * 时间精确到毫秒，并且转成字符串
     *
     * @return String
     */
    public static String formateDbDateToString(Date object) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss", Locale.CHINA);
        String dateString = formatter.format(object);
        return dateString;
    }

    /**
     * 时间精确到毫秒加上1W以内的随机数
     *
     * @return String
     */
    public static String randomTimer() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS", Locale.CHINA);
        String dateString = formatter.format(new Date());
        int randNum = (int) (Math.random() * 10);
        dateString += randNum;
        return dateString;
    }


    public static void verifyTime(long startTime, long endTime) {
        if (startTime <= endTime) {
            throw new WhyException(ResultEnum.TIME_IS_INCORRECTLY_FILLED_OUT);
        }
    }

    public static void verifyTime(long startTime, long endTime, long registerStartTime, long registerEndTime) {
        if (!(registerStartTime < registerEndTime && registerEndTime < startTime && startTime < endTime)) {
            throw new WhyException(ResultEnum.TIME_IS_INCORRECTLY_FILLED_OUT);
        }
    }

    /**
     * 转换数据库long型日期至字符串类型
     *
     * @param millsec long类型时间
     */
    public static String longToString(long millsec) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        Date date = new Date(millsec);
        return formatter.format(date);
    }

    /**
     * 转换数据库long型日期至字符串类型
     *
     * @param millsec long类型时间
     */
    public static String longToString3(long millsec) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        Date date = new Date(millsec);
        return formatter.format(date);
    }

    /**
     * 转换数据库long型日期至字符串类型(去掉秒)
     *
     * @param millsec long类型时间
     */
    public static String longToString2(long millsec) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
        Date date = new Date(millsec);
        return formatter.format(date);
    }

    /**
     * 转换数据库long型日期至字符串类型
     *
     * @param startTime long类型时间
     * @param endTime   long类型时间
     * @return 2018-10-1 至 2018-10-2
     */
    public static String longToString4Y_M_D(long startTime, long endTime) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        String time = formatter.format(new Date(startTime)) + " 至 " + formatter.format(new Date(endTime));
        return time;
    }

    /**
     * 转换数据库long型日期至字符串类型
     *
     * @param startTime long类型时间
     * @param endTime   long类型时间
     * @return 10:30 至13:00
     */
    public static String longToString4H_M(long startTime, long endTime) {
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm", Locale.CHINA);
        String time = formatter.format(new Date(startTime)) + "至" + formatter.format(new Date(endTime));
        return time;
    }

    /**
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return 返回格式 2018-09-13 11:41:57至20:41:57
     */
    public static String longToString(long startTime, long endTime) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        String time = simpleDateFormat.format(new Date(startTime)) + "至" + simpleDateFormat.format(new Date(endTime));
        return time;
    }


    /**
     * 转换数据库long型日期至字符串类型
     *
     * @param millsec
     * @return
     */
    public static String formateMillsecDateToStr2(long millsec) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        Date date = new Date(millsec);
        return formatter.format(date);
    }

    public static Date formateMillsecToDate(long millsec) {
        Date date = new Date(millsec);
        return date;
    }

    public static Date string2Time(String dateString) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        Date date = null;
        try {
            date = formatter.parse(dateString);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return date;
    }

    public static Long StringToLong(String timeString) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        Date date = null;
        Long long1 = null;
        try {
            date = formatter.parse(timeString);
            long1 = date.getTime();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return long1;
    }

    public static Long StringToLong4(String timeString) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
        Date date = null;
        Long long1 = null;
        try {
            date = formatter.parse(timeString);
            long1 = date.getTime();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return long1;
    }

    public static Long StringToLong5(String timeString) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        Date date = null;
        Long long1 = null;
        try {
            date = formatter.parse(timeString);
            long1 = date.getTime();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return long1;
    }

    public static Long StringToLong6(String timeString) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy月MM日dd", Locale.CHINA);
        Date date = null;
        Long long1 = null;
        try {
            date = formatter.parse(timeString);
            long1 = date.getTime();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return long1;
    }

    public static Long StringToLong3(String timeString) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM", Locale.CHINA);
        Date date = null;
        Long long1 = null;
        try {
            date = formatter.parse(timeString);
            Calendar date1 = Calendar.getInstance();
            date1.setTime(date);
            date1.set(Calendar.MONTH, date1.get(Calendar.MONTH) + 1);
            Date endDate = formatter.parse(formatter.format(date1.getTime()));
            long1 = endDate.getTime();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return long1;
    }

    public static Long StringToLong2(String timeString) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM", Locale.CHINA);
        Date date = null;
        Long long1 = null;
        try {
            date = formatter.parse(timeString);
            long1 = date.getTime();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return long1;
    }

    /**
     * 手机号码加密| 身份证号码加密 |电话号码加密
     * @param phoneNum
     * @return 此方法用户隐私信息加密
     */

    /**
     * 手机号码加密| 身份证号码加密 |电话号码加密
     *
     * @param oldData    原始值
        加密的内容长度  4个*
     * @return
     */
    public static String BASENumEncrypt(String oldData) {
        int len = oldData.length();
        int endIndex = len - 4;
        int beginIndex = endIndex - 4;
        String star = "";
        for (int i = 0; i < 4; i++) {
            star = new StringBuilder().append(star).append("*").toString();
        }
        return oldData.substring(0, beginIndex) + star + oldData.substring(endIndex, len);
    }

    /**
     * 取月份
     *
     * @param dateString
     * @return
     * @throws ParseException
     */
    public static Date string2Month(String dateString) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM", Locale.CHINA);
        Date date = null;
        try {
            date = formatter.parse(dateString);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return date;
    }

    public static Date StringToDate(String timeString) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        Date date = null;
        try {
            date = formatter.parse(timeString);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return date;
    }

    /**
     * 传当前时间获取这一周的日期
     *
     * @param mdate
     * @return
     */


    public static List<Date> dateToWeek(Date mdate) {
        int b = mdate.getDay();
        Date fdate;
        List<Date> list = new ArrayList<Date>();
        Long fTime = mdate.getTime() - b * 24 * 3600000;
        for (int a = 1; a <= 7; a++) {
            fdate = new Date();
            fdate.setTime(fTime + (a * 24 * 3600000)); //一周从周日开始算，则使用此方式
            //fdate.setTime(fTime + ((a-1) * 24*3600000)); //一周从周一开始算，则使用此方式
            list.add(a - 1, fdate);
        }
        return list;
    }

    /**
     * 传当前时间获取今天至n天后的日期
     *
     * @param mdate
     * @param n     天数
     * @return
     */


    public static List<Date> dateToWeek(Date mdate, int n) {
        int b = mdate.getDay();
        Date fdate;
        List<Date> list = new ArrayList<Date>();
        Long fTime = mdate.getTime() - b * 24 * 3600000;
        for (int a = 1; a <= n; a++) {
            fdate = new Date();
            fdate.setTime(fTime + (a * 24 * 3600000)); //一周从周日开始算，则使用此方式
            //fdate.setTime(fTime + ((a-1) * 24*3600000)); //一周从周一开始算，则使用此方式
            list.add(a - 1, fdate);
        }
        return list;
    }

    /**
     * 转换数据库long型日期至字符串类型
     *
     * @param millsec
     * @return 例如 08:08
     */
    public static String formateMillsecDateToStr4(long millsec) {
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm", Locale.CHINA);
        Date date = new Date(millsec);
        return formatter.format(date);
    }


    /**
     * 获取week
     *
     * @param date
     * @return
     */
    public static String getWeek(Date date, int n) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, n);
        int week_index = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (week_index < 0) {
            week_index = 0;
        }
        return weeks[week_index];
    }

    /**
     * 获取week
     *
     * @param date
     * @return
     */
    public static String getWeek(Date date) {
        String[] weeks = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int week_index = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (week_index < 0) {
            week_index = 0;
        }
        return weeks[week_index];
    }

    /**
     * 获取第n天后的日期
     *
     * @param date
     * @param n
     * @return
     */
    public static String getDate(Date date, int n) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, n);
        date = calendar.getTime();
        return sdf.format(date);
    }


    public static List<String> getThisMonthDay(int year, int month) {
        List<String> list = new ArrayList<String>();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal = Calendar.getInstance();
//		cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), 1);
        cal.set(year, month, 1);
        cal.add(Calendar.MONTH, 0);
        cal.add(Calendar.DATE, -1);
        String lastDay = sf.format(cal.getTime());
        String aDay = "";
        int i = 1;
        while (!lastDay.equals(aDay)) {
            cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), i);
            aDay = sf.format(cal.getTime());
            list.add(sf.format(cal.getTime()));
            i++;
        }
        return list;
    }


    /**
     * 查询从今天起N天(暂为14天)
     *
     * @return
     */
    public static List<String> getFromTodayNDays() {
        List<String> list = new ArrayList<String>();
        Date date = new Date();
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for (int i = 0; i < 14; i++) {
            if (sdf.format(cal.getTime()).equals(sdf.format(date))) {
                cal.add(Calendar.DATE, 0);
            }
            list.add(sdf.format(cal.getTime()));
            cal.add(Calendar.DATE, 1);
        }
        return list;
    }

    /**
     * 查询从今天起 到 结束时间endTime前三天  的数据
     *
     * @param endTime
     * @return
     */
    public static List<String> getbeforeTodayNDays(String endTime) {
        List<String> list = new ArrayList<String>();
        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
        try {
            long day = (sd.parse(endTime).getTime() - sd.parse(formateDbDate(new Date())).getTime()) / (24 * 60 * 60 * 1000);
            Calendar cal = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            if (day > 3) {
                Date date = new Date();
                for (int i = 0; i < day - 2; i++) {
                    if (sdf.format(cal.getTime()).equals(sdf.format(date))) {
                        cal.add(Calendar.DATE, 0);
                    }
                    list.add(sdf.format(cal.getTime()));
                    cal.add(Calendar.DATE, 1);
                }
            } else {
                list.add(sdf.format(cal.getTime()));
            }
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 获得明天的凌晨的时间
     */
    public static Date getTommerDate(Date beginDate) {
        SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        date.set(Calendar.DATE, date.get(Calendar.DATE) + 1);
        Date endDate = null;
        try {
            endDate = dft.parse(dft.format(date.getTime()));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return endDate;
    }

    /**
     * 获得后天的凌晨的时间
     */
    public static Date getDayAfterTomorrowDate(Date beginDate) {
        SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        date.set(Calendar.DATE, date.get(Calendar.DATE) + 2);
        Date endDate = null;
        try {
            endDate = dft.parse(dft.format(date.getTime()));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return endDate;
    }

    /**
     * 获得今天凌晨的时间
     */
    public static Date getTodayDate(Date beginDate) {
        SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        date.set(Calendar.DATE, date.get(Calendar.DATE));
        Date endDate = null;
        try {
            endDate = dft.parse(dft.format(date.getTime()));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return endDate;
    }

    /**
     * 获得n小时之前的时间
     */
    public static Long getBeforHourDate(Date datetime, int hourNum) {
        Calendar date = Calendar.getInstance();
        date.setTime(datetime);
        date.set(Calendar.HOUR, date.get(Calendar.HOUR) - hourNum);
        return date.getTimeInMillis();
    }

    /**
     * 获得n小时之前的时间
     */
    public static Date getBeforHourToDate(Date datetime, int hourNum) {
        Calendar date = Calendar.getInstance();
        date.setTime(datetime);
        date.set(Calendar.HOUR, date.get(Calendar.HOUR) - hourNum);
        return date.getTime();
    }

    /**
     * N小时之后的时间
     *
     * @param datetime
     * @param hourNum
     * @return
     */
    public static Date getAfterHourToDate(Date datetime, int hourNum) {
        Calendar date = Calendar.getInstance();
        date.setTime(datetime);
        date.set(Calendar.HOUR, date.get(Calendar.HOUR) + hourNum);
        return date.getTime();
    }

    /**
     * 获得N分钟之后的时间
     */
    public static Long getAfterHourDate(Date datetime, int minuteNum) {
        Calendar date = Calendar.getInstance();
        date.setTime(datetime);
        date.set(Calendar.MINUTE, date.get(Calendar.MINUTE) + minuteNum);
        return date.getTimeInMillis();
    }

    /**
     * 获得N分钟之后的时间
     */


    public static Long datetime4num(int num) {
        Date datetime = new Date();
        Calendar date = Calendar.getInstance();
        date.setTime(datetime);
        date.set(Calendar.DATE, date.get(Calendar.DATE) + num);
        return date.getTimeInMillis();
    }


    /**
     * 获得上一个月
     */
    public static Date getLastMonth(Date beginDate) {
        SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM", Locale.CHINA);
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        date.set(Calendar.MONTH, date.get(Calendar.MONTH) - 1);
        Date endDate = null;
        try {
            endDate = dft.parse(dft.format(date.getTime()));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return endDate;
    }

    /**
     * 获得下一个月
     */
    public static Date getTommerMonth(Date beginDate) {
        SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM", Locale.CHINA);
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        date.set(Calendar.MONTH, date.get(Calendar.MONTH) + 1);
        Date endDate = null;
        try {
            endDate = dft.parse(dft.format(date.getTime()));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return endDate;
    }

    /**
     * 获得下下一个月
     */
    public static Date getTommerMonth2(Date beginDate) {
        SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM", Locale.CHINA);
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        date.set(Calendar.MONTH, date.get(Calendar.MONTH) + 2);
        Date endDate = null;
        try {
            endDate = dft.parse(dft.format(date.getTime()));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return endDate;
    }

    /**
     * 获得这个月
     */
    public static Date getTodayMonth(Date beginDate) {
        SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM", Locale.CHINA);
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        date.set(Calendar.MONTH, date.get(Calendar.MONTH));
        Date endDate = null;
        try {
            endDate = dft.parse(dft.format(date.getTime()));
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return endDate;
    }


    /**
     * 获得这个日期中的日（在这个月是几号）
     */
    public static int getDay(Date beginDate) {
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        int day = 0;
        day = date.get(Calendar.DAY_OF_MONTH);
        return day;
    }

    /**
     * 功能描述：返回小时
     *
     * @param millsec 日期
     * @return 返回小时
     */
    public static int getDay(long millsec) {
        Date date = new Date(millsec);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.DATE);
    }


    /**
     * 获得这个日期中的月
     */
    public static int getMonth(Date beginDate) {
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        int month = 0;
        month = date.get(Calendar.MONTH) + 1;
        return month;
    }

    /**
     * 获得这个日期中的年
     */
    public static int getYear(Date beginDate) {
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        int year = 0;
        year = date.get(Calendar.YEAR);
        return year;
    }

    /**
     * 计算年龄
     *
     * @param beginDate
     * @return
     */

    public static int getAge(Date beginDate) {
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        int year = date.get(Calendar.YEAR);
        Calendar date2 = Calendar.getInstance();
        date2.setTime(new Date());
        int year2 = date2.get(Calendar.YEAR);
        return year2 - year;
    }

    /**
     * 获得
     * 例如 : 周四 5月5号 20:08
     */
    public static String getOrderBody(Date beginDate) {
        String[] weeks = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(beginDate);
        int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (week_index < 0) {
            week_index = 0;
        }
        int month = cal.get(Calendar.MONTH) + 1;
        String monthstr = "";
        if (month < 10) {
            monthstr = "0" + month;
        } else {
            monthstr = "" + month;
        }
        int day = cal.get(Calendar.DAY_OF_MONTH);
        String daystr = "";
        if (day < 10) {
            daystr = "0" + day;
        } else {
            daystr = "" + day;
        }
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        String hourStr = "";
        if (hour < 10) {
            hourStr = "0" + hour;
        } else {
            hourStr = "" + hour;
        }
        int min = cal.get(Calendar.MINUTE);
        String minStr = "";
        if (min < 10) {
            minStr = "0" + min;
        } else {
            minStr = "" + min;
        }
        return weeks[week_index] + " " + monthstr + "月" + daystr + "日 " + hourStr + ":" + minStr;
    }

    /**
     * 获取电话号码的后6位,并且加密
     */
    public static String getPhonelastsix(String phone) {
        String str = phone.substring(phone.length() - 6, phone.length());
        return SHA1.getDigestOfString(str);
    }

    /**
     * 字符串日期格式胡
     *
     * @param dateString
     * @return
     * @throws ParseException
     */
    public static Date formatString2DateYYMMDD(String dateString) {
        DateFormat dateFormat;
        dateFormat = new SimpleDateFormat("yy-MM-dd", Locale.CHINA);
        dateFormat.setLenient(false);
        String strs = StringUtils.replaceChars(dateString, "/", "-");
        Date timeDate = null;
        try {
            timeDate = dateFormat.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Date dateTime = new Date(timeDate.getTime());
        return dateTime;
    }

    /**
     * 格式化日期
     *
     * @param str
     * @return
     * @throws ParseException
     */
    public static Date formatString2DateYYYMMDDHHMMSS(String str) {
        DateFormat dateFormat;
        dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        dateFormat.setLenient(false);
        String strs = StringUtils.replaceChars(str, "/", "-");
        Date timeDate = null;
        try {
            timeDate = dateFormat.parse(strs);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Date dateTime = new Date(timeDate.getTime());
        return dateTime;
    }

    /**
     * 将日期转换成ISO 8601的格式
     *
     * @author Glory
     */
    public static String formatDateToISO8601(Date date) {
        DateFormat dateFormat;
        dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.CHINA);
        return dateFormat.format(date);

    }

    /**
     * 功能描述：返回小时
     *
     * @param millsec 日期
     * @return 返回小时
     */
    public static int getHour(long millsec) {
        Date date = new Date(millsec);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(Calendar.HOUR_OF_DAY);
    }

    /**
     * 功能描述：返回明天凌晨时间
     */
    public static Date getTimeOfnextday() {
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.add(Calendar.DAY_OF_MONTH, 1);
        return cal.getTime();
    }

    /**
     * 获取两个日期中间的所有时间
     *
     * @param startDay
     * @param endDay
     * @return
     */
    public static List<String> getBetweenDays(String startDay, String endDay) {
        return Stream.iterate(LocalDate.parse(startDay), localDate -> localDate.plusDays(1))
                .limit(ChronoUnit.DAYS.between(LocalDate.parse(startDay), LocalDate.parse(endDay)) + 1)
                .map(LocalDate::toString)
                .collect(Collectors.toList());
    }


    /**
     * Jsoup转换工具
     *
     * @param url
     * @return
     */
    public static String documentBody(String url) {
        Element doc = Jsoup.parseBodyFragment(url).body();
        Elements pngs = doc.select("img[src]");
        String httpHost = "http://jcjjwhy.oss-cn-hangzhou.aliyuncs.com/";
        for (Element element : pngs) {
            String imgUrl = element.attr("src");
            String suffixName = imgUrl.substring(imgUrl.lastIndexOf("/") + 1, imgUrl.length());
            url = url.replace(imgUrl, httpHost + suffixName);
        }
        return url;
    }

    /**
     * Jsoup转换工具2
     * 针对word
     *
     * @param url
     * @return
     */
    public static String documentBody2(String url) {
        Element doc = Jsoup.parseBodyFragment(url).body();
        Elements pngs = doc.select("img[src]");
        String httpHost = "http://jcjjwhy.oss-cn-hangzhou.aliyuncs.com/";
        String path = "";
        for (Element element : pngs) {
            String imgUrl = element.attr("src");
            url = url.replace(imgUrl, httpHost + imgUrl);
            File file = new File(uploadUrl + imgUrl);
            String fileName = UUID.randomUUID() + "." + imgUrl.substring(imgUrl.lastIndexOf(".") + 1);
            OSSClient ossClient = new OSSClient(ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECRET);
            ossClient.putObject(BUCKET_NAME, fileName, file);
            ossClient.shutdown();
            String config = serverPath + fileName;
            url = url.replace(httpHost + imgUrl, config);

        }
        return url;
    }

    /**
     * 去富文本标签工具
     */
    public static String noHtmlContent(String str) {
        return str.replaceAll("</?[^><]*>", "").replaceAll("&nbsp;", "");
    }

    /**
     * 范围内随机生成n个不同的随机数
     *
     * @param min 最小值
     * @param max 最大值
     * @param n
     * @return
     */
    public static int[] randomCommon(int min, int max, int n) {
        if (n > (max - min + 1) || max < min) {
            return null;
        }
        int[] result = new int[n];
        int count = 0;
        while (count < n) {
            int num = (int) (Math.random() * (max - min)) + min;
            boolean flag = true;
            for (int j = 0; j < n; j++) {
                if (num == result[j]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                result[count] = num;
                count++;
            }
        }
        return result;
    }


    /**
     * 根据UUID 生成orderId
     *
     * @return
     */
    public static String getOrderIdByUUId() {
        int machineId = 1;//最大支持1-9个集群机器部署
        int hashCodeV = UUID.randomUUID().toString().hashCode();
        if (hashCodeV < 0) {//有可能是负数
            hashCodeV = -hashCodeV;
        }
        // 0 代表前面补充0
        // 15 代表长度为15
        // d 代表参数整数数型
        return machineId + String.format("%015d", hashCodeV);
    }

    /**
     * 根据UUID和时间戳生成订单号
     *
     * @return
     */
    public static String getOrderIdByTimeAndUUId() {
        Long systemtimeLong = systemtimeLong();
        String orderId = getOrderIdByUUId();
        orderId = orderId.substring(0, 5) + systemtimeLong.toString();
        return orderId;
    }

    public static String getticketCollectionCode(){
        return String.valueOf((int) ((Math.random()*9+1)*10000000));
    }

    /**
     * 获取某天后的毫秒值
     *
     * @param day 天数
     * @return
     */
    public static long getMillisByDay(int day) {
        Long systemtimeLong = systemtimeLong();
        systemtimeLong += day * 86400000;
        return systemtimeLong;

    }




    /**
     * BenaUtils.copyProperties 忽略Null值
     * @param source
     * @return
     */
    public static String[] getNullPropertyNames (Object source) {
        final BeanWrapper src = new BeanWrapperImpl(source);
        java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();

        Set<String> emptyNames = new HashSet<String>();
        for(java.beans.PropertyDescriptor pd : pds) {
            Object srcValue = src.getPropertyValue(pd.getName());
            if (srcValue == null){
                emptyNames.add(pd.getName());
            }
        }
        String[] result = new String[emptyNames.size()];
        return emptyNames.toArray(result);
    }

    /**
     * 数值判断
     */
    public static long numericalJudgment(long num){
        /*long startTime = BaseTools.systemtimeLong();
        //---//
        if(0 <= num && num <= 9){
            return 10;
        }else if(10 <= num && num <100){
            return 100;
        }else if(100 <= num && num < 200){
            return 200;
        }else if(200 <= num && num < 300){
            return 300;
        }else if(300 <= num && num < 400){
            return 400;
        }else if(400 <= num && num < 500){
            return 500;
        }else if(500 <= num && num < 600){
            return 600;
        }else{
            return 1000;
        }*/
        /*long i = 0;
        //获取多少位数
        char[] chars = String.valueOf(num).toCharArray();
        if(chars.length>2){
            long y =(long)Math.ceil(num/10.0);
            i= (long) (100*Math.ceil(y/10.0));
        }else {
            i=(long) (10* Math.ceil(num/10.0));
        }*/
        num = (num/100 +1)*100;
        return num;

    }
}
